package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RedDate {
    public static void main(String[] args) {
        //基本分组
        String regex =
                "(\\d{4})-(\\d{1,2})-(\\d{2})"; // 匹配日期格式
        String text = "2024-3-15";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            System.out.println("group(0) = " + matcher.group(0));
            System.out.println("年:" + matcher.group(1)); // 2024
            System.out.println("月:" + matcher.group(2)); // 03
            System.out.println("日:" + matcher.group(3)); // 15
        }
        //非捕获分组
        String regex2 = "(?:https?)://(?:www\\.)?(.+)"; // 非捕获协议和www

    }
}
